/*******************************************************************************
*
* (c) Copyright 2014 Freescale Semiconductor
*
****************************************************************************//*!
*
* @file     SIM.h
*
* @author   Salvador Zendejas
*
* @version  0.0.1
*
* @date      Aug 22, 2014
*
* @brief    System Integration Module configuration for Kinetis K.
*
*******************************************************************************/
#ifndef SIM_H_
#define SIM_H_

/*******************************************************************************
* Includes
*******************************************************************************/
#include "derivative.h" /* Include peripheral declarations */


/*******************************************************************************
* Constants and macros
*******************************************************************************/

#if _DEBUG_ && _CLKOUT_
	#undef SIM_SOPT2_CLKOUTSEL(x)
	#define SIM_SOPT2_CLKOUTSEL(x)                   (((uint32_t)(((eCLKOUTsel_t)(x))<<SIM_SOPT2_CLKOUTSEL_SHIFT))&SIM_SOPT2_CLKOUTSEL_MASK)
#endif
/*******************************************************************************
* Types Definitions
*******************************************************************************/
typedef enum{
	_K1x_Fam = 0x1,
	_K2x_Fam,
	_K3x_Fam,
	_K4x_Fam,
	_K5x_Fam,
	_K6x_Fam,
	_K7x_Fam,
}eKinetisFam_t;

typedef enum{
	_Kx0_Subfam,
	_Kx1_Subfam,
	_Kx2_Subfam,
	_Kx3_Subfam,
	_Kx4_Subfam,
	_Kx5_Subfam,
	_Kx6_Subfam
}eKinetisSubFam_t;

typedef enum{
	_K_Series,
	_L_Series,
	_W_Series = 0x5,
	_V_Series
}eKinetisSeriesID_t;

typedef enum{
	_32Pin = 0x2,
	_48Pin = 0x4,
	_64Pin = 0x5,
	_80Pin,
	_81Pin,
	_100Pin,
	_121Pin,
	_144Pin,
	_CustomPinOut,
	_169Pin,
	_256Pin = 0xE
}ePIN_ID_t;

typedef enum{	//Selects the 32 kHz clock source (ERCLK32K) for LPTMR
	e_OSC32KCLK,		//System oscillator (OSC32KCLK)
	e_Reserved,			//Not use
	e_RTC_32_368kOsc,	//RTC 32.768kHz oscillator
	e_LPO_1kHz	
}Clk32kSrc_t;	//32K oscillator clock select

typedef enum{	//Selects the 32 kHz clock source (ERCLK32K) for LPTMR
	e_FlexBusCLKOUT,		//System oscillator (OSC32KCLK)
	e_ReservedCLKOut,			//Not use
	e_FlashClock,
	e_LPO_Clock1kHz,
	e_MCGIRCLK,
	e_RTC_32_368kHzCLK,	//RTC 32.768kHz oscillator
	e_OSCERCLK0,
	e_IRC_48kMHz
}eCLKOUTsel_t;	//CLKOUT select

typedef struct{
	eKinetisFam_t	eFAMILYID;
	eKinetisSubFam_t eSUBFAMID;
	eKinetisSeriesID_t eSERIESID;
	uint8_t u8REVID;
	ePIN_ID_t ePINID;
}sMCU_Info_t;
/*******************************************************************************
* Global function prototypes
*******************************************************************************/
void vfn_SIM_Init(void);

/*******************************************************************************
* Local function prototypes
*******************************************************************************/
static sMCU_Info_t tfn_GetInfoDeviceID(void);
#endif /* SIM_H_ */
